//
//  ImageBrowerUntils.m
//  GoldBook
//
//  Created by wmz on 2021/8/28.
//  Copyright © 2021 wmz. All rights reserved.
//

#import "ImageBrowerUntils.h"
#import "YBImageBrowser.h"
@implementation ImageBrowerUntils

+ (void)showImageBrower:(BaseCellModel*)model{
    if (!model) return;
    return [ImageBrowerUntils showImageBrower:@[model] current:0];
}

+ (void)showImageBrower:(NSArray<BaseCellModel*>*)dataSource current:(NSInteger)index{
    NSMutableArray <YBIBImageData*>*marr = [NSMutableArray new];
    for (BaseCellModel *model in dataSource) {
        if (!model.isSelected) {
            YBIBImageData *data = [YBIBImageData new];
            if (model.image) {
                data.image = ^UIImage * _Nullable{
                    return model.image;
                };
            }else{
                if ([model.imageTitle isKindOfClass:NSString.class]) {
                    if ([model.imageTitle hasPrefix:@"http"]) {
                        data.imageURL = [NSURL URLWithString:model.imageTitle];
                    } else if ([model.imageTitle hasPrefix:@"/"] && [model.imageTitle hasSuffix:@".jpg"]) {
                        data.imageURL = [NSURL URLWithString:GNFillImage(model.imageTitle)];
                    }
                } else if ([model.imageTitle isKindOfClass:UIImage.class]) {
                    data.image = ^UIImage * _Nullable{
                        return (UIImage*)model.imageTitle;
                    };
                }
            }
            [marr addObject:data];
        }
    }
    YBImageBrowser *browser = [YBImageBrowser new];
    browser.dataSourceArray = marr;
    browser.autoHideProjectiveView = false;
    browser.currentPage = index;
    [browser show];
}
@end
